import pytest
import requests

from apis.member_delete_api import MemberDeleteApi
from apis.batch_member_info_api import BatchMemberApi
from apis.member_modify_avatar_api import MemberModifyAvatarApi
from apis.member_group_relocate_api import MemberGroupRelocateApi
from apis.member_search_api import MemberSearchApi
from apis.member_unblock_api import MemberUnblockApi
from config.config import BASE_URL
from core.tools import md5
import random


@pytest.fixture(scope="module")
def register():
    """ 注册会员,返回uuid """
    url = f"{BASE_URL}/api/App/User/Register"
    # 数据(载荷)
    payload = {
        "app_key": "A9286FB9391AD1DE7496B7CCB83D4D12",
        "username": f"test_{random.randint(1, 100)}",
        "password": md5("123456")
    }
    r = requests.post(url=url, json=payload)
    r_json: dict = r.json()
    uuid = r_json.get("data").get("uuid")
    return uuid

@pytest.fixture(scope="function")
def login():
    """管理员登录，返回token"""
    url = f"{BASE_URL}/api/App/User/Login"
    # 数据(载荷)
    payload = {
        "app_key": "A9286FB9391AD1DE7496B7CCB83D4D12",
        "username": "agonyer_1024",
        "password": "7f22bf39aaf5ce5980111c3587bef5b5"
    }
    r = requests.post(url=url, json=payload)
    r_json: dict = r.json()
    token = r_json.get("data").get("token")
    return token


@pytest.fixture(scope="session")
def modify_avatar_api():
    """修改会员头像"""
    return MemberModifyAvatarApi()


@pytest.fixture(scope="session")
def batch_member_info_api():
    """批量获取会员信息"""
    return BatchMemberApi()


@pytest.fixture(scope="session")
def member_delete_api():
    """删除会员"""
    return MemberDeleteApi()


@pytest.fixture(scope="session")
def member_group_relocate_api():
    """会员分组"""
    return MemberGroupRelocateApi()


@pytest.fixture(scope="session")
def member_search_api():
    """搜索会员"""
    return MemberSearchApi()


@pytest.fixture(scope="session")
def member_unblock_api():
    """解封号会员"""
    return MemberUnblockApi()


